package com.dreamsail.service.help;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @Descriotion MqttMessageSender
 * @Author wfq
 * @Date 2023/2/27
 */
@Component
@AllArgsConstructor
public class MqttMessageSender {
    public static final Logger log = LoggerFactory.getLogger(MqttMessageSender.class);

    private MqttGateway mqttGateway;

    public void send(String message) {
        log.info("MqttMessageSender send >>>>>>message>>>{}", message);
        mqttGateway.sendToMqtt(message);
    }

    /**
     * 发送mqtt消息
     *
     * @param topic   主题
     * @param message 内容
     * @return void
     * @author Jackpot
     * @date 2021/9/7 12:20 下午
     */
    public void send(String topic, String message) {
        log.info("MqttMessageSender send >>> topic  {} >>>message>>>{}", topic, message);
        mqttGateway.sendToMqtt(topic, message);
    }

    /**
     * 发送包含qos的消息
     *
     * @param topic       主题
     * @param qos         质量
     * @param messageBody 消息体
     * @return void
     * @author Jackpot
     * @date 2021/9/7 12:21 下午
     */
    public void send(String topic, int qos, JSONObject messageBody) {
        log.info("MqttMessageSender send >>> topic  {} >>>message>>>{}", topic, messageBody);
        mqttGateway.sendToMqtt(topic, qos, messageBody.toString());
    }

    /**
     * 发送包含qos的消息
     *
     * @param topic   主题
     * @param qos     质量
     * @param message 消息体
     * @return void
     * @author Jackpot
     * @date 2021/9/7 12:21 下午
     */
    public void send(String topic, int qos, byte[] message) {
        log.info("MqttMessageSender send >>> topic  {} >>>message>>>{}", topic, message);
        mqttGateway.sendToMqtt(topic, qos, message);
    }
}
